package com.company.bookstore.validator.user_admin_module;


import com.company.bookstore.exception.user_admin_module.CustomException;

import java.util.concurrent.ConcurrentHashMap;

/**
 * ValidatorFactory
 * 验证器工厂
 *
 * 统一动作 验证
 *
 * 编写 abs验证类 留空验证逻辑 定义准备事项和返回的内容
 *
 * 子类验证器重写 模板方法 的验证逻辑
 *
 * 将子类验证器汇集到这个工厂类中，通过name 值 获取对应的validator 验证器对传入的类进行验证。
 *
 * @blame Android Team
 */
public class ValidatorFactory {
    private static final ConcurrentHashMap<String,ValidatorHandler> VALIDATORS = new ConcurrentHashMap<>();
    public static boolean Invoke(String name,Object body) throws NoSuchMethodException, CustomException {
        return VALIDATORS.get(name).validator(body);
    }
    public static void register(String name,ValidatorHandler validatorHandler){
        VALIDATORS.put(name,validatorHandler);
    }
}
